<template>
  <div class="new_auction_withdraw">
    <c-title :hide="false" text="提现"></c-title>
    <div class="account_management_top">
      <div class="account_management_top_left">可提现金额：{{ can_withdraw_income }}</div>
    </div>
    <div class="withdrawBox">
      <div class="withdrawBox_top">可提现金额</div>
      <div class="numInpBox">
        <span class="small">{{ $i18n.t("money") }}</span>
        <van-field v-model="value" type="number" placeholder="请输入金额" :border="false" />
        <div class="inp_r" @click="tapAll">全部提现</div>
      </div>
    </div>
    <div class="btn" @click="save_withdrawTap" v-if="tag == 'balance'">提现到余额</div>
    <div class="btn" @click="save_withdrawTap" v-else>提现到收入</div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      value: "",
      tag: "",
      can_withdraw_income: ""
    };
  },
  activated() {
    this.tag = this.$route.params.tag;
    this.getData();
  },
  methods: {
    tapAll() {
      if (this.can_withdraw_income == 0) {
        this.$toast("提现失败，可提现金额为0");
        return;
      }
      this.value = this.can_withdraw_income;
    },
    async getData() {
      let urlstr = "plugin.new-auction.frontend.income";
      if (this.tag == "balance") {
        urlstr = "plugin.new-auction.frontend.money.memberInfo";
      }
      let { data, msg, result } = await $http.post(urlstr, {}, "");
      if (result) {
        if (this.tag == "balance") {
          this.can_withdraw_income = data.money;
        } else {
          this.can_withdraw_income = data.can_withdraw_income;
        }
      } else {
        this.$toast(mgs);
      }
    },
    async save_withdrawTap() {
      let strUrl = "";
      if (this.tag == "income") {
        strUrl = "plugin.new-auction.frontend.income.withdraw";
      } else {
        strUrl = "plugin.new-auction.frontend.money.withdraw";
      }
      let { data, msg, result } = await $http.post(strUrl, { amount: this.value }, "");
      if (result) {
        this.$toast(msg);
        this.value = "";
        this.getData();
      } else {
        this.$toast(msg);
      }
    }
  }
};
</script>
<style lang="scss" scoped>
.account_management_top {
  height: 6.66rem;
  background: linear-gradient(180deg, #f15353 0%, #f5f5f5 100%);
  .account_management_top_left {
    padding: 1.69rem 0 0 0.97rem;
    font-weight: bold;
    font-size: 0.81rem;
    color: #ffffff;
    box-sizing: border-box;
    text-align: left;
    line-height: 0.85rem;
  }
}
.withdrawBox {
  margin: -3.3rem 0.75rem 0 0.75rem;
  background: #ffffff;
  border-radius: 0.63rem;
  padding: 1rem 0.75rem;
  box-sizing: border-box;
  .withdrawBox_top {
    font-size: 0.81rem;
    color: #00001c;
    text-align: left;
  }

  .numInpBox {
    display: flex;
    align-items: center;
    margin-top: 1.3rem;
    .van-cell {
      padding: 0;
    }
    .small {
      flex-shrink: 0;
      font-weight: bold;
      font-size: 0.94rem;
      margin-right: 0.5rem;
    }
    .inp_r {
      flex-shrink: 0;
      font-size: 0.81rem;
      color: #f15353;
    }
  }
}
.btn {
  margin: 1.56rem 0.75rem;
  height: 2.5rem;
  background: #f15353;
  border-radius: 1.25rem;
  line-height: 2.5rem;
  text-align: center;
  font-weight: 500;
  font-size: 0.94rem;
  color: #ffffff;
}
</style>
